<?php
namespace app\admin\controller;
use think\Controller;
use think\Request;
use think\Session;
use think\Db;
use app\admin\controller\Common;

class Index extends Common
{
    public function index(){
        $str=session::get('name');
        $admin['name']=$str;
        $power=Db::table('hd_admin')->field('power')->where($admin)->find();
        $this->assign('power',$power);

        //饼状图  要求的条件是type 类型  不同类型，得到其总数，返回到前端
       
            //查询admin数据库，获取个人信息


            $wh['name']=$str;
            $aaaa=Db::table('hd_admin')->where($wh)->find();
            $this->assign('peson',$aaaa);
            return view();
        }
        
    
    public function index_v1(){
        //总数量
        $all=Db::table('hd_connection')->where('isdelete',0)->select();

        $listall=count($all);
        //在库的藏品
        $dataa = Db::view('hd_connection')
            ->view('hd_state', ['id' => 's_id'], 'hd_state.cid=hd_connection.id')
            ->where('isdelete=0 and isnew=1 and state=0')
            ->select();
      //  dump($dataa);die;
        $dataa=count($dataa);

        //出库产品
    
       $aalist = Db::view('hd_connection')
       ->view('hd_state', ['id' => 's_id'], 'hd_state.cid=hd_connection.id')
       ->where('isdelete=0 and isnew=1 and state=1')
       ->select();
       $listaa=count($aalist);
      
        //转库
        $datac = Db::view('hd_connection')
            ->view('hd_state', ['id' => 's_id'], 'hd_state.cid=hd_connection.id')
            ->where('isdelete=0 and isnew=1 and state=2')
            ->select();
        $datacc=count($datac);

        $this->assign('aaa',$dataa);
        $this->assign('aaall',$listall);
        $this->assign('datacc',$datacc);
         $this->assign('aalist',$aalist);
        $this->assign('listaa',$listaa);


        //获取月份时间

  $goods=array();
        $datar=Db::view('hd_connection')
            ->view('hd_state', ['id' => 's_id', 'state' => 'state', 'time' => 's_time','isnew'=>'isnew'], 'hd_state.cid=hd_connection.id')

            ->select();
   // var_dump($datar);
           
            
            $away1=array();
            $away2=array();
            $away3=array();
            $away4=array();
            $away5=array();
            $away6=array();
            $away7=array();
            $away8=array();
            $away9=array();
            $away10=array();
            $away11=array();
            $away12=array();
            $away01=array();
            $away02=array();
            $away03=array();
            $away04=array();
            $away05=array();
            $away06=array();
            $away07=array();
            $away08=array();
            $away09=array();
            $away010=array();
            $away011=array();
            $away012=array();
        foreach($datar as $k=>$v){
          
            //通过循环将时间戳转换为年月时间
            $time=$v['time'];                    //首次入库时间
            $aa=date("m",$time);                 //首次入库时间的月份
            $aa2=date("Y",$time);                 //首次入库时间的年份
           

            $s_time=$v['s_time'];                //每次更新的时间
            $aaa=date("m",$s_time);               //每次更新的时间的月份
            $aaa2=date("Y",$s_time);               //每次更新的时间的年份
            $datar[$k]['s_time_m']=$aaa;
            $datar[$k]['s_time_y']=$aaa2;

            $xtime=date("Y",time());                  //判断当前的年份
            $state=$v['state'];
          
           
            if($datar[$k]['s_time_y']==$xtime){
                if($state==0){
 

                  //判断数据的状态
                    if($aaa==1){                      //一月份入库
                        $away1[]=$datar;                   
                    }
                    if($aaa==2){                      //2月份入库
                        $away2[]=$v;
                    }
                    if($aaa==3){                      //3月份入库
                        $away3[]=$v;
                    }
                    if($aaa==4){                      //4月份入库
                        $away4[]=$v;
                    }
                    if($aaa==5){                      //5月份入库
                        $away5[]=$v;
                    }
                    if($aaa==6){                      //6月份入库
                        $away6[]=$v;
                    }
                    if($aaa==7){                      //7月份入库
                        $away7[]=$v;
                    }
                    if($aaa==8){                      //8月份入库
                        $away8[]=$v;
                    }
                    if($aaa==9){                      //9月份入库
                        $away9[]=$v;
                       
                      
                    }
                    if($aaa==10){                      //10月份入库
                        $away10[]=$v;
                       
                    }
                    if($aaa==11){                      //11月份入库
                        $away11[]=$v;
                    }
                    if($aaa==12){                      //12月份入库
                        $away12[]=$v;
                    }
                               
            
                }
                if($state!=0){
               
                    if($aaa==1){                      //1月份出转库
                        $away01[]=$v;
                       
                    }
                    if($aaa==2){                      //2月份出转库
                        $away02[]=$v;
                    }
                    if($aaa==3){                      //3月份出转库
                        $away03[]=$v;
                    }
                    if($aaa==4){                      //4月份出转库
                        $away04[]=$v;
                    }
                    if($aaa==5){                      //5月份出转库
                        $away05[]=$v;
                    }
                    if($aaa==6){                      //6月份出转库
                        $away06[]=$v;
                    }
                    if($aaa==7){                      //7月份出转库
                        $away07[]=$v;
                    }
                    if($aaa==8){                      //8月份出转库
                        $away08[]=$v;
                    }
                    if($aaa==9){                      //9月份出转库
                        $away09[]=$v;
                    }
                    if($aaa==10){                      //10月份出转库
                        $away010[]=$v;
                      
                    
                    }
                    if($aaa==11){                      //11月份出转库
                        $away011[]=$v;
                    }
                    if($aaa==12){                      //12月份出转库
                        $away012[]=$v;
                    }
                }
                 
          
            }
        }
   
       
        if($away1==''){
            $away1_1=0;
        }else{
            $away1_1=count($away1);
        }
        
        if($away01==''){
            $away1_2=0;
        }else{
            $away1_2=count($away01);
        }
      
        $this->assign('away1_1',$away1_1);
        $this->assign('away1_2',$away1_2);

        
        if($away2==''){
            $away2_1=0;
        }else{
            $away2_1=count($away2);
        }
        
        if($away02==''){
            $away2_2=0;
        }else{
           $away2_2=count($away02);
        }
       
        $this->assign('away2_1',$away2_1);
        $this->assign('away2_2',$away2_2);
        
        
        if($away3==''){
            $away3_1=0;
        }else{
            $away3_1=count($away3);
        }
        
        if($away03==''){
            $away3_2=0;
        }else{
            $away3_2=count($away03);
        }
       
        $this->assign('away3_1',$away3_1);
        $this->assign('away3_2',$away3_2);
        
        
        if($away4==''){
            $away4_1=0;
        }else{
            $away4_1=count($away4);
        }
        
        if($away04==''){
            $away4_2=0;
        }else{
            $away4_2=count($away04);
        }
       
        $this->assign('away4_1',$away4_1);
        $this->assign('away4_2',$away4_2);

        
        if($away5==''){
            $away5_1=0;
        }else{
            $away5_1=count($away5);
        }
        
        if($away05==''){
            $away5_2=0;
        }else{
            $away5_2=count($away05);
        }
      
        $this->assign('away5_1',$away5_1);
        $this->assign('away5_2',$away5_2);

        
        
        if($away6==''){
            $away6_1=0;
        }else{
            $away6_1=count($away6);
        }
        
        if($away06==''){
            $away6_2=0;
        }else{
            $away6_2=count($away06);
        }
       
        $this->assign('away6_1',$away6_1);
        $this->assign('away6_2',$away6_2);

        
        
        if($away7==''){
            $away7_1=0;
        }else{
            $away7_1=count($away7);
        }
        
        if($away07==''){
             $away7_2=0;
        }else{
            $away7_2=count($away07);
        }
       
        $this->assign('away7_1',$away7_1);
        $this->assign('away7_2',$away7_2);

        
        
        if($away8==''){
           $away8_1=0;
        }else{
           $away8_1=count($away8);
        }
        
        if($away08==''){
            $away8_2=0;
        }else{
             $away8_2=count($away08);
        }
        
        $this->assign('away8_1',$away8_1);
        $this->assign('away8_2',$away8_2);

        
        
        if($away9==''){
            $away9_1=0;
        }else{
            $away9_1=count($away9);
        }
        
        if($away09==''){
           $away9_2=0;
        }else{
           $away9_2=count($away09);
        }
       
        $this->assign('away9_1',$away9_1);
        $this->assign('away9_2',$away9_2);

        
        
        if($away10==''){
             $away10_1=0;
           
        }else{
             $away10_1=count($away10);           
        }
     
   
        
        if($away010==''){
            $away10_2=0;
        }else{
            $away10_2=count($away010);
        }
       
        $this->assign('away10_1',$away10_1);
        $this->assign('away10_2',$away10_2);

        
        if($away11==''){
           $away11_1=0;
        }else{
            $away11_1=count($away11);
        }
        
        if($away011==''){
           $away11_2=0;
        }else{
            $away11_2=count($away011);
        }
        
        $this->assign('away11_1',$away11_1);
        $this->assign('away11_2',$away11_2);

        
        
        if($away12==''){
            $away12_1=0;
        }else{
            $away12_1=count($away12);
        }
        
        if($away012==''){
            $away12_2=0;
        }else{
            $away12_2=count($away012);
        }
       
        $this->assign('away12_1',$away12_1);
        $this->assign('away12_2',$away12_2);

        return view();
    }




    public function tuichu(){
        session(null);
        $this->redirect('login/login',0, '页面跳转中...');
    }



    public function collect(){

        $str=session::get('name');
        $admin['name']=$str;
        $power=Db::table('hd_admin')->field('power')->where($admin)->find();
        $this->assign('power',$power);

        //view方法连表查询
      /*  if (request()->isGet()) {
            $a = input('post.');
            foreach ($a as $k => $v) {
                if ($v == '') {
                    unset($a[$k]);
                }
            }
            $a['isdelete'] = 0;
            $a['isnew']=1;
            $datac = Db::view('hd_connection')
                ->view('hd_state', ['id' => 's_id', 'state' => 'state', 'why' => 'why'], 'hd_state.cid=hd_connection.id')
                ->where($a)
                // ->limit(2)
                ->select();
            //图片处理
            //转化图片路径
            foreach ($datac as $k => $v) {
                $img = $v['image'];
                $a = explode(',', $img);
                $stt='_';
                $a=substr_replace($a,$stt,9,0);
                $datac[$k]['image2'] = $a;
            }
            //传参
        //   $this->assign('page',$page);
            $this->assign('datac', $datac);
            //渲染图层
            return $this->fetch();
        }else {*/

            //数据接收加判断
            $isdelete = input('isdelete');
            $state = input('state');

            if ($isdelete == 0) {
                $datac = Db::view('hd_connection')
                    ->view('hd_state', ['state' => 'state', 'why' => 'why'], 'hd_state.cid=hd_connection.id')
                    ->where('isdelete=0 and isnew=1')
                    ->select();
            }
            if ($state == 1) {
                $datac = Db::view('hd_connection')
                    ->view('hd_state', ['id' => 's_id', 'state' => 'state', 'why' => 'why'], 'hd_state.cid=hd_connection.id')
                    ->where('isdelete=0 and isnew=1 and state=1')
                    ->select();
            }
            if ($state == 0) {
                $datac = Db::view('hd_connection')
                    ->view('hd_state', ['id' => 's_id', 'state' => 'state', 'why' => 'why'], 'hd_state.cid=hd_connection.id')
                    ->where('isdelete=0 and isnew=1 and state=0')
                    ->select();
            }
            if ($state == 2) {
                $datac = Db::view('hd_connection')
                    ->view('hd_state', ['id' => 's_id', 'state' => 'state', 'why' => 'why'], 'hd_state.cid=hd_connection.id')
                    ->where('isdelete=0 and isnew=1 and state=2')
                    ->select();
            }

            //转化图片路径
            foreach ($datac as $k => $v) {
                $img = $v['image'];
                $a = explode(',', $img);
                $stt = '_';
                $a = substr_replace($a, $stt, 9, 0);
                $datac[$k]['image2'] = $a;
            }

            $this->assign('datac', $datac);
            //删除
            $id = input('id');
            if (empty($id)) {
            } else {
                $wh['id'] = $id;
                $ttt = Db::table('hd_connection')->where($wh)->update(['isdelete' => 1]);

            }
            return view();
        }

}